package cn.j2e.portal.controller;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.j2e.portal.dto.SystemDto;
import cn.j2e.portal.service.ISystemService;
import cn.j2web.core.commons.ResponseResult;
import cn.j2web.core.commons.ResponseResultUtil;
import cn.j2web.core.utils.mapper.BeanMapper;
import cn.j2e.portal.domain.System;

@Controller
@RequestMapping("/systemController")
public class SystemController {

	 private static Logger log = LoggerFactory.getLogger(SystemController.class);
	
	@Resource(name = "systemServiceImpl")
	private ISystemService systemService;

	@RequestMapping(value="/gotoSysPage")
	public String gotoSysPage(){
		log.debug("gotoSysPage");
		return "system/system";
	}
	
	@RequestMapping(value="/saveOrUpdateSystem")
	@ResponseBody
	public ResponseResult addSystem(SystemDto systemDto){
		// 操作的返回的数据结构
		ResponseResult responseResult=null;
		try {
			System system = new System();
			BeanMapper.copy(systemDto, system);
			systemService.saveSystem(system);
			responseResult =ResponseResultUtil.createResponse(true,"保存成功！", null);
		} catch (RuntimeException e) {
			responseResult =ResponseResultUtil.createResponse(true,"保存失败！", e.getMessage());
		}
		return responseResult;
	}
	

	@RequestMapping("/validateCodeVal")
	@ResponseBody
	public boolean validateSys(String sysSign,String codeValB){
		return systemService.validateCodeValSysSgin(sysSign,codeValB);
	}
	
	
}
